use std::thread::sleep;
use std::time::{Duration, SystemTime};
use rsntp::{SntpClient, AsyncSntpClient};
use crate::lexpose;
/* 发起 ntp对时 */
pub(crate) async fn start_ntp(adr: &str) -> Option<i128>{
    let client = AsyncSntpClient::new();
    lexpose::print_info_log(format!("ntp对时：{} 准备好，开始加载", adr));
    match client.synchronize(adr).await {
        Ok(result) => {
            let date_time = result.datetime();
            let now_time = SystemTime::now();
            match date_time.into_system_time() {
                Ok(ntp_t) => {
                    let ntp_time = ntp_t.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos();
                    let now_time_n = now_time.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos();
                    lexpose::print_info_log(format!("ntp对时，{} 加载成功", adr));
                    let space_time = ntp_time as i128 - now_time_n as i128;
                    Some(space_time)
                }
                Err(_) => {
                    lexpose::print_info_log(format!("ntp对时，{} 加载失败", adr));
                    None
                }
            }
        }
        Err(_) => {
            lexpose::print_info_log(format!("ntp对时，{} 加载失败", adr));
            None
        }
    }
}




























